import 'package:finance_app/generated/json/base/json_convert_content.dart';
import 'package:finance_app/generated/json/base/json_field.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/entities/business_contact_entity.dart';
import 'package:finance_app/src/entities/format/service_and_product_entity.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';
import 'package:finance_app/src/page/dashboard/products_services/quantity_page.dart';

class QuotationEntity with JsonConvert<QuotationEntity> {
  @JSONField(name: "data_type")
  String dataType;
  int id;
  @JSONField(name: "company_id")
  int companyId;
  @JSONField(name: "contact_id")
  int contactId;
  @JSONField(name: "invoice_id")
  dynamic invoiceId;
  String number;
  @JSONField(name: "issued_at")
  String issuedAt;
  @JSONField(name: "delivery_at")
  String deliveryAt;
  @JSONField(name: "due_at")
  String dueAt;
  @JSONField(name: "currency_code")
  String currencyCode;
  num subtotal;
  @JSONField(name: "exclusive_tax_amount")
  double exclusiveTaxAmount;
  @JSONField(name: "inclusive_tax_amount")
  int inclusiveTaxAmount;
  @JSONField(name: "discount_type")
  dynamic discountType;
  @JSONField(name: "discount_amount")
  int discountAmount;
  num total;
  dynamic notes;
  String status;
  @JSONField(name: "created_by")
  dynamic createdBy;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;
  List<QuotationItems> items;

  BusinessContactEntity contact;
}

class QuotationItems with JsonConvert<QuotationItems> {
  @JSONField(name: "data_type")
  String dataType;
  int id;
  @JSONField(name: "company_id")
  int companyId;
  @JSONField(name: "quotation_id")
  int quotationId;
  String type;
  @JSONField(name: "type_id")
  int typeId;
  String name;
  int quantity;
  @JSONField(name: "currency_code")
  String currencyCode;
  @JSONField(name: "tax_id")
  int taxId;
  SettingDataTax tax;
  @JSONField(name: "discount_type")
  String discountType;
  @JSONField(name: "discount_value")
  num discountValue;

  num price;
  @JSONField(name: "nett_price")
  num nettPrice;
  @JSONField(name: "is_tax_inclusive")
  int isTaxInclusive;
  @JSONField(name: "tax_amount")
  double taxAmount;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;

  ServiceAndProductEntity toServiceAndProduct() {
    ServicesEntity servicesEntity = ServicesEntity();
    ProductEntity productEntity = ProductEntity();
    if (type == 'product') {
      productEntity
        ..id = typeId
        ..name = name
        ..isTaxInclusive = isTaxInclusive
        ..price = price
        ..currencyCode = currencyCode
        ..discountType = discountType
        ..discountValue = discountValue
        // ..tax =
        ..taxId = taxId
        ..tax = this.tax;
    } else {
      servicesEntity
        ..id = typeId
        ..name = name
        ..isTaxInclusive = isTaxInclusive
        ..price = price
        ..currencyCode = currencyCode
        ..discountType = discountType
        ..discountValue = discountValue
        // ..tax =
        ..taxId = taxId
        ..tax = this.tax;
    }
    return ServiceAndProductEntity()
      ..services = servicesEntity
      ..product = productEntity
      ..number = quantity;
  }
}
